import os
import cv2 as cv
import numpy as np
from scipy import signal
from matplotlib import pyplot


if __name__ == "__main__":
    img_path = "./img/ruihua/beiwen2.jpeg"  # 定义图像的完整路径
    src_img = cv.imread(img_path, cv.IMREAD_GRAYSCALE)  # 读入图像
    # cv.namedWindow("src_img", cv.WINDOW_AUTOSIZE)
    cv.imshow("src_img", src_img)  # 显示未处理的原图
    # 调用函数实现低通掩膜
    Low_pass_filter = cv.blur(src_img, (3, 3))  # 参数kernel是奇数，可自由调整
    cv.imshow("Low pass filter", Low_pass_filter)
    # 调用函数实现中值滤波
    Median_filter = cv.medianBlur(src_img, 3)
    cv.imshow("Median filter", Median_filter)
    # 调用opencv的函数实现高斯滤波 （此处的高斯滤波与高斯掩膜有差别）
    Gaussian_filter = cv.GaussianBlur(src_img, (3, 3), 0)
    cv.imshow("Gaussian filter", Gaussian_filter)
    # 图像锐化
    kernel_sharpen_1 = np.array([[0, -1, 0], [-1, 5, -1], [0, -1, 0]])  # 拉普拉斯掩膜
    kernel_sharpen_2 = np.array([[-1, -1, -1], [-1, 9, -1], [-1, -1, -1]])
    output_1 = cv.filter2D(src_img, -1, kernel_sharpen_1)
    output_2 = cv.filter2D(src_img, -1, kernel_sharpen_2)
    cv.imshow('sharpen_1 Image', output_1)
    cv.imshow('sharpen_2 Image', output_2)
    cv.waitKey(0)
    cv.destroyAllWindows()